package com.example.widgetapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class ListViewActivity02 extends AppCompatActivity {
    private List<Manghe> manghelist = new ArrayList<>();
    private Goods goods = new Goods();

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_listview);

//        initManghes();
        /*MangheAdapter myMangheAdapter = new MangheAdapter(ListViewActivity02.this,R.layout.manghe_item,manghelist);*/

        manghelist = goods.getGoodList();

        MangheAdapterY2 mangheAdapterY2 = new MangheAdapterY2(ListViewActivity02.this, R.layout.manghe_item, manghelist);

        ListView listView = findViewById(R.id.list_view);
        listView.setAdapter(mangheAdapterY2);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//                Manghe manghe = manghelist.get(i);
//                Toast.makeText(ListViewActivity02.this,manghe.getName(), Toast.LENGTH_SHORT).show();

                Intent intent = new Intent(ListViewActivity02.this, MainActivity2.class);
                intent.putExtra("goodsId", i);
                startActivity(intent);
            }
        });
    }

    private void initManghes(){   /*数据实例化*/
        Manghe mlgb = new Manghe("密林古堡系列",R.drawable.mlgb);
        manghelist.add(mlgb);

        Manghe rsrx = new Manghe("人生如戏系列",R.drawable.rsrx);
        manghelist.add(rsrx);

        Manghe xmrc = new Manghe("熊猫热潮系列",R.drawable.xmrc);
        manghelist.add(xmrc);

        Manghe slzy = new Manghe("森林之夜系列",R.drawable.slzy);
        manghelist.add(slzy);

        Manghe cwdj = new Manghe("宠物度假系列",R.drawable.cwdj);
        manghelist.add(cwdj);

        Manghe sexz = new Manghe("十二星座系列",R.drawable.sexz);
        manghelist.add(sexz);

        Manghe shdx = new Manghe("社会大学系列",R.drawable.shdx);
        manghelist.add(shdx);

        Manghe szg = new Manghe("水族馆系列",R.drawable.szg);
        manghelist.add(szg);

        Manghe zxyjl = new Manghe("仲夏夜精灵系列",R.drawable.zxyjl);
        manghelist.add(zxyjl);

        Manghe tklx = new Manghe("太空旅行系列",R.drawable.tklx);
        manghelist.add(tklx);

    }
}